/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.perf;

import android.app.Application;
import android.util.Log;
import android.os.Looper;
import android.os.Message;

import android.os.SystemClock;

/**
 * Top-level Application class for the Perf service.
 */
public class PerfService extends Application {
	private static final String LOG_TAG = "PerfService";

    @Override
    public void onCreate() {
		Log.d(LOG_TAG,"PerfService onCreate enter");
		Looper.setObserver(mMessageObserver);
        PerfTest test = new PerfTest();
        test.start();
    }


	private Looper.Observer mMessageObserver = new Looper.Observer() {
		public Object messageDispatchStarting() {
			long dispatchStart = SystemClock.uptimeMillis();
			return dispatchStart;
		}

		public void messageDispatched(Object token, Message msg) {
			long actualTime = SystemClock.uptimeMillis() - (long) token;
			Log.d(LOG_TAG, "message " + msg.what + " took " + actualTime + "ms "
                  + Thread.currentThread().getName() + " h="
                  + msg.getTarget().getClass().getName() + " c=" + msg.getCallback() + " m=" + msg.what);
		}

		public void dispatchingThrewException(Object token, Message msg, Exception exception) {

		}
	};
}

